Add test for checkout_tree
authorFelix Krull <f_krull@gmx.de>
Fri, 24 May 2019 22:59:22 +0000 (00:59 +0200)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:54 +0000 (12:53 -0400)
rust-bindings/rust/tests/repo.rs
rust-bindings/rust/tests/util/mod.rs

index c3a773c1fda1f40169b4bfa978b221f0c67419ee..7f8a7d119f63984c04bc0a32ba0d40313c6cadf9 100644 (file)
@@ -8,8 +8,9 @@ extern crate maplit;
 mod util;
 use util::*;
 
+use gio::prelude::*;
 use gio::NONE_CANCELLABLE;
-use ostree::prelude::*;
+use glib::prelude::*;
 use ostree::{ObjectName, ObjectType};
 
 #[test]
@@ -31,7 +32,7 @@ fn should_commit_content_to_repo_and_list_refs_again() {
 #[test]
 fn should_traverse_commit() {
     let test_repo = TestRepo::new();
-    let checksum = test_repo.test_commit();
+    let checksum = test_repo.test_commit("test");
 
     let objects = test_repo
         .repo
@@ -61,3 +62,40 @@ fn should_traverse_commit() {
         objects
     );
 }
+
+#[test]
+fn should_checkout_tree() {
+    let test_repo = TestRepo::new();
+    let _ = test_repo.test_commit("test");
+
+    let checkout_dir = tempfile::tempdir().expect("checkout dir");
+    let file = test_repo
+        .repo
+        .read_commit("test", NONE_CANCELLABLE)
+        .expect("read commit")
+        .0
+        .downcast::<ostree::RepoFile>()
+        .expect("RepoFile");
+    let info = file
+        .query_info("*", gio::FileQueryInfoFlags::NONE, NONE_CANCELLABLE)
+        .expect("file info");
+    test_repo
+        .repo
+        .checkout_tree(
+            ostree::RepoCheckoutMode::User,
+            ostree::RepoCheckoutOverwriteMode::None,
+            &gio::File::new_for_path(checkout_dir.path().join("test-checkout")),
+            &file,
+            &info,
+            NONE_CANCELLABLE,
+        )
+        .expect("checkout tree");
+
+    let testfile_path = checkout_dir
+        .path()
+        .join("test-checkout")
+        .join("testdir")
+        .join("testfile");
+    let testfile_contents = std::fs::read_to_string(testfile_path).expect("test file");
+    assert_eq!("test\n", testfile_contents);
+}
index 923a2f9b2773691da93b8a24730ad7d3530c8c27..8d92ea8ae5347035d2fa0c93a513512511948df3 100644 (file)
@@ -1,7 +1,6 @@
 use gio::NONE_CANCELLABLE;
 use glib::prelude::*;
 use glib::GString;
-use ostree::prelude::*;
 use std::path::Path;
 
 #[derive(Debug)]
@@ -23,9 +22,9 @@ impl TestRepo {
         TestRepo { dir, repo }
     }
 
-    pub fn test_commit(&self) -> GString {
+    pub fn test_commit(&self, ref_: &str) -> GString {
         let mtree = create_mtree(&self.repo);
-        commit(&self.repo, &mtree, "test")
+        commit(&self.repo, &mtree, ref_)
     }
 }